package src.A_JavaBase;

public class Demo07 {
    public static void main(String[] args) {
        //一维数组：3种定义方式，4种写法
        int arr1[] = {1,2,3}; //按习惯不推荐
        int[] arr2 = {1,2,3}; //静态初始化
        int[] arr3 = new int[]{1,2,3};
        int[] arr4 = new int[3]; //动态初始化：包括默认初始化(0)
        arr4[0] = 1; arr4[1] = 2; arr4[2] = 3;
        for(int i : new Demo07().fz(arr1)){
            System.out.println(i);
        }
        //二维数组，和一维数组一样
        int arrs1[][] = {{1},{2,3},{4,5,6}};
        int[][] arrs2 = {{1},{2,3},{4,5,6}};
        int[][] arrs3 = new int[][]{{1},{2,3},{4,5,6}};
        int[][] arrs4 = new int[2][3];
        int[][][][][][][][][][][][] arrs5 = new int[2][3][4][9][2][3][4][9][2][3][4][9]; //多维数组
        arrs4[0][0] = 1; arrs4[0][1] = 2; arrs4[0][2] = 3;
        arrs4[1][0] = 4; arrs4[1][1] = 5; arrs4[1][2] = 6;
        for (int[] ints : arrs4){
            for (int i : ints){
                System.out.print(i+"\t");
            }
            System.out.println();
        }
    }

    //一维数组元素反转
    public int[] fz(int[] arr){
        int[] is = new int[arr.length];
        for (int i = 0, j = is.length-1; i < arr.length; i++, j--) {
            is[j] = arr[i];
        }
        return is;
    }

}
